<template>
	<view class="logn">
		<view class="top">
			<image class="img" src="../../static/img.png" mode=""></image>
		</view>
		<view class="title">
			欢迎使用
		</view>
		<view class="text">
			立即登录，开启全新世界
		</view>
		<!-- 登录 -->
		<view class="bot_info">
			<button class="button" @tap="login()">授权登录</button>
			<view class="bot_text" @tap='back'>
				取消授权
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '../../api/api.js'
	export default {
		data() {
			return {
				code: '',
			}
		},
		onLoad() {
			uni.login({
				provider: 'weixin',
				success: (loginRes) => {
					this.code = loginRes.code;
					console.log(this.code)
				}
			});
		},
		onShow() {
		},
		onBackPress() {
		},
		methods: {
			// 微信登录
			login(e) {
				var json = {
					js_code: this.code,
				}
				login(json).then(res => {
					if (res.code == 0) {
						uni.setStorageSync('token', res.data.token);
						uni.navigateBack({
							delta:-1,
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
				
			},


			
			// 获取手机号
			getphonenumber(e) {
				bind_mobile({
					iv: e.detail.iv,
					encryptedData: e.detail.encryptedData

				}).then(res => {
					if (res.code == 0) {
						uni.navigateBack({
							delta: 1
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
				console.log('phone', e)
			},

			// 取消授权
			back() {
				uni.switchTab({
					url: '../index/index'
				})

			},
		}
	}
</script>

<style lang="less">
	.top {
		display: flex;
		justify-content: center;

		.img {
			width: 250rpx;
			height: 250rpx;
			margin-top: 150rpx;

		}
	}

	// 大标题
	.title {
		text-align: center;
		font-size: 40rpx;
		font-weight: bold;
		padding-top: 20rpx;

	}

	// 小标题
	.text {
		text-align: center;
		padding: 30rpx 0;
		color: #808080;
		font-size: 28rpx;
	}

	// 登录
	.button {
		background-color: rgba(212, 48, 48, 1);
		color: #FFFFFF;
		font-size: 30rpx;
		// font-weight: bold;
		padding: 5rpx 0;
		margin: 10rpx 70rpx 0 70rpx;
	}

	.bot_text {
		text-align: center;
		padding: 50rpx 0;
		font-size: 30rpx;
		// font-weight: bold;
		color: #808080;
	}
</style>